package DAO;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;

public class RepositorioBasico {
	
	protected Session session;
	
	protected SessionFactory factory;
	
	protected Transaction tx;
	
	
	public RepositorioBasico(){
		AnnotationConfiguration acf = new AnnotationConfiguration();
		acf.configure();
		this.factory = acf.buildSessionFactory();
	}
	
	
	protected void abreSessao(){
		this.session = factory.openSession();
		this.tx = session.beginTransaction();
	}
	
	
	protected void fechaSessao(){
		tx.commit();
		session.flush();
		session.close();		
	}
}
